package DataStrucures;

public class ArrayBinaryTreeDemo {
    public static void main(String[] args) {
        int[]arr={1,2,3,4,5,6,7};
        ArrBinaryTree arrBinaryTree=new ArrBinaryTree(arr);
        arrBinaryTree.preOrder(0);
        System.out.println();
        arrBinaryTree.infixOrder(0);
        System.out.println();
        arrBinaryTree.postOrder(0);
    }


}
class ArrBinaryTree{
    private int[] arr;

    public ArrBinaryTree(int[] arr) {
        this.arr = arr;
    }
    public void preOrder(int index){
        if(arr.length==0){
            System.out.println("数组位空");
            return;
        }
        System.out.print(arr[index]+" ");
        if((index*2+1)<arr.length){
            preOrder(index*2+1);
        }
        if((index*2+2)<arr.length){
            preOrder(index*2+2);
        }
    }
    public void infixOrder(int index){
        if(arr.length==0){
            System.out.println("数组位空");
            return;
        }

        if((index*2+1)<arr.length){
            infixOrder(index*2+1);
        }
        System.out.print(arr[index]+" ");
        if((index*2+2)<arr.length){
            infixOrder(index*2+2);
        }
    }
    public void postOrder(int index){
        if(arr.length==0){
            System.out.println("数组位空");
            return;
        }

        if((index*2+1)<arr.length){
            postOrder(index*2+1);
        }
        if((index*2+2)<arr.length){
            postOrder(index*2+2);
        }
        System.out.print(arr[index]+" ");
    }
}
